package com.mts.indicatorserver.yearmanage.controller

import com.mts.indicatorcommon.yearmanage.vo.YearManageVo
import com.mts.indicatorcommon.yearmanage.search.YearManageSearch
import com.mts.indicatorserver.yearmanage.service.YearManageService
import com.mts.javacommon.jpabase.ResultVoUtil
import com.mts.javacommon.jpabase.ResultVo
import com.mts.javacommon.jpabase.PageVo
import com.mts.javacommon.jpabase.PageUtil
import org.springframework.data.domain.Page
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.tags.Tag
import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.*
import jakarta.validation.Valid


/**
 * <pre>
 *       前端控制器
 * </pre>
 *
 * @author Johnny
 * @date 2025-08-22
 */
@Tag(name = "")
@RestController
@RequestMapping("/api/yearManage")
class YearManageController(
        private val yearManageService: YearManageService
        ) {

        /**
         * 带条件查询的 分页接口
         */
        @GetMapping("/listByCondition")
        @Operation(summary = "根据条件查询 (分页)")
        fun listByCondition(
                @Parameter(description = "查询条件")
            yearManageSearch: YearManageSearch,

                @Parameter(description = "分页条件")
                pageVo: PageVo
        ): ResultVo<Page<YearManageVo>> {
        val page = yearManageService.listByCondition(
    yearManageSearch,
                                          PageUtil.initPage(pageVo)
        )
                return ResultVoUtil.success(page)
    }

        @PostMapping("/add")
        @Operation(summary = "新增信息")
        fun add(
                @RequestBody @Valid
                @Parameter(description = "新增的数据")
            yearManageVo: YearManageVo
        ): ResultVo<Void> {
    yearManageService.add(yearManageVo)
    return ResultVoUtil.success()
}

        @PostMapping("/edit")
        @Operation(summary = "修改信息")
        fun edit(
                @RequestBody @Valid
                @Parameter(description = "修改的数据")
            yearManageVo: YearManageVo
        ): ResultVo<Void> {
    yearManageService.edit(yearManageVo)
    return ResultVoUtil.success()
}

        @GetMapping("/delete/{id}")
        @Operation(summary = "删除信息")
        fun delete(
                @Parameter(description = "id", example = "1")
                @PathVariable id: Long
        ): ResultVo<Void> {
    yearManageService.delete(id)
    return ResultVoUtil.success()
}

        @PostMapping("/deletes")
        @Operation(summary = "批量删除信息")
        fun deletes(
                @RequestBody
                @Parameter(description = "要删除的id列表")
                ids: Array<Long>
        ): ResultVo<Void> {
    val idList = ids.toList()
        yearManageService.deletes(idList)
    return ResultVoUtil.success()
}
}
